<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/12/16
 * Time: 9:40
 */
declare(strict_types=1);
namespace app\api\controller;

use app\BaseController;
use app\common\business\Sms as SmsBus;
class Sms extends BaseController{
    public function code() : object
    {
        $phoneNumber = input('phone_number','','trim');
        $data= [
            'phone_number' => $phoneNumber
        ];
        //1.验证数据
        try{
           validate( \app\api\validate\User::class)->scene('send_code')->check($data);
        }catch (\think\exception\ValidateException $e){
            return show(config('status.error'),$e->getError());
        }
        //2.business层处理数据 参数（手机号,验证码长度）
        if(SmsBus::sendCode($phoneNumber,6,'ali')){
            return show(config('status.success'),'发送验证码成功');
        }
        return show(config('status.error'),'发送验证失败');
    }
}